package org.bookshare.validator.error;

import org.benetech.beans.error.ValidationError;


/**
 * Represents a missing resource.
 * @author Reuben Firmin
 */
public final class MissingResourceValidationError implements ValidationError {

    private String context;
    private String resourceName;
    private boolean required;

    /**
     * A resource is missing within the specific context (e.g. "OPF Manifest"),
     * with the specified name (e.g. "images/myImage.gif"). The required flag
     * specifies whether the resource is optional or not.
     * @param context never null
     * @param resourceName never null
     * @param required is it optional?
     */
    public MissingResourceValidationError(final String context,
        final String resourceName, final boolean required)
    {
        this.context = context;
        this.resourceName = resourceName;
        this.required = required;
    }

    /**
     * {@inheritDoc}
     */
    public Severity getSeverity() {
        return required ? Severity.ERROR : Severity.WARNING;
    }

    /**
     * The context that the resource is missing from.
     * @return never null
     */
    public String getContext() {
        return context;
    }

    /**
     * The name of the missing resource.
     * @return never null.
     */
    public String getResourceName() {
        return resourceName;
    }

    /**
     * {@inheritDoc}
     */
    public String toString() {
        return (required ? "Resource: " : "Optional resource: ") + resourceName
            + " is missing from: " + context;
    }
}
